package com.csjy.migration.hnnd.workflow;

import com.csjy.migration.hnnd.BusinessTool;
import com.csjy.migration.hnnd.DbUtil;
import com.csjy.migration.hnnd.ProgramArgument;
import com.csjy.migration.hnnd.Tool;
import com.csjy.migration.hnnd.annotation.Task;
import com.csjy.migration.hnnd.business.NdBpmCreditExtensionSc;
import com.csjy.migration.hnnd.business.SourceBusinessData;
import com.fasterxml.jackson.core.JsonProcessingException;

import javax.script.ScriptException;
import java.sql.SQLException;
import java.util.*;

/**
 * 调查报告评审、项目展期、项目复议、项目增量、项目续议、项目评审流程
 */
public class ItemAuditHny extends WorkflowMigration {

  private Object reviewSecretary = null;
  private Map managerAReportAffix = null;
  private Map managerBReportAffix = null;
  private String auditType = "调查报告评审";

  private NdBpmCreditExtensionSc ndBpmCreditExtensionSc;

  public ItemAuditHny(DbUtil sourceDbUtil, DbUtil targetDbUtil, SourceBusinessData sourceData, ProgramArgument programArgument, String projectId, String procInstId, Map procInstRow) throws Exception {
    super(sourceDbUtil, targetDbUtil, sourceData, programArgument, projectId, procInstId, procInstRow);
    this.customInitData();
  }

  @Override
  public void customInitData() throws Exception {
    this.curBizType = "xmsp";
    ndBpmCreditExtensionSc = new NdBpmCreditExtensionSc(sourceDbUtil, targetDbUtil, sourceData, programArgument,projectId,procInstId);
    auditType = this.procInstRow.get("WFDISPLAYNAME").toString();
  }

  @Override
  public void customInsertOrUpdateData() throws Exception {
    ndBpmCreditExtensionSc.start();
    // 生成担保协议字号
    generateGuaranteeWordAndNumber();

  }

  /**
   * 生成担保协议字号
   */
  private synchronized void generateGuaranteeWordAndNumber() throws SQLException {
    if(!isRunning){
      return;
    }

    if(!this.procInstRow.get("WFDISPLAYNAME").toString().equals("调查报告评审")) {
      return;
    }

    String taskName = this.curJbpmTaskInstanceRow.get("NAME_").toString();
    if(taskName.equals("项目评审@负责人独立审批签字")
        || taskName.equals("项目评审@独立评审总经理审批签字")
        || taskName.equals("项目评审@独立评审董事长审批签字")
        || taskName.equals("项目评审@评审会主任审批签字")){
      Calendar date = Calendar.getInstance();
      Integer year = date.get(Calendar.YEAR);
      Integer number = 1;
      String sql = "select greatest(10000,nvl(max(guarant_agree_number),1)) as NUM from ND_PROJECT_INFO t where guarant_agree_word="+year;
      List<Object> numList = this.targetDbUtil.selectSingleColumn(sql , new ArrayList());
      if (numList.size()>0) {
        number = Integer.parseInt(numList.get(0).toString()) + 1;
      }
      String no = "湘农信担保协议字["+year+"]第["+number+"]号";
      String sql1 = "update nd_project_info set guarant_agree_number="+number
          +",guarant_agree_word="+year+",guarant_agree_no='"+no
          +"' where id='"+this.projectId+"' and not exists (select id from nd_project_info where "
          +" guarant_agree_number="+number+" and guarant_agree_word="+year+")";
      this.targetDbUtil.updateByParams(sql1, new ArrayList(), true);
    }
  }

  @Task("项目评审@A经理提交评审报告")
  public void migrationAJltjpsbg() throws Exception {
    // 基础数据：审批意见、结论、附件（单个附件、附件列表、附件类型）
    // 临时业务数据
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("all", new String[]{"task1535432889889tjsh","提交审核"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("all", new String[]{"task1535530755459tjsh","提交审核"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("all", new String[]{"task1560243446581tjsh","提交审核"});
    }

    this.curAffixType = "dcbg";
    this.curAffixTypeCommon = "ajltjpsbg";

    Map wfAffixNotionSingleFileObj = this.findFirstWfAffixNotionObjByWkflag(2);
    this.setCommonData(true,wfAffixNotionSingleFileObj == null ? null : wfAffixNotionSingleFileObj.get("INTMARK").toString());

    // 关联在保项目总额（老流程中没有，若有也是不准确的，应该要实时进行查询)
    this.curCustomData.put("totalCoverageMoney",this.sourceData.getBtItemBasic().get(0).get("CURRASSURESUM"));

    //  项目基本信息(从老数据钟拿)
    String[] ndProjectInfoFields = new String[] {
        "office" ,"chiefAuditor","proType","applyCoverage","applyTime","isMicro","guaranteeRate","explain","bank"
        ,"lendingMethod","industry","industryCode","productName","customerSource","institution1","institution2"
        ,"institution3","summary","marginRatioHy","chargingMethod","revolvingLoan","everyAverageMoney"};
    getDataField(ndProjectInfoFields);

    this.curCustomData.put("titleChaKan","查看调查报告");

    // A报告
    managerAReportAffix = this.curTaskSingleAffix;

    this.actHiVarinstMap.put("voteBat",0);

    // 项目展期评审
    Map<String,Object> taskParamMap = this.initTaskParamMap();
    ndBpmCreditExtensionSc.getTaskParamMap().put(curJbpmTaskInstanceId, taskParamMap);
  }

  @Task("项目评审@项目B经理审核")
  public void migrationXmBjlsh() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("通过", new String[]{"exclusiveGateway1552888660754tg","通过"});
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1552888660754tg","通过"});
      this.curModelMap.put("提交审批", new String[]{"exclusiveGateway1552888660754tg","通过"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过", new String[]{"exclusiveGateway1598954612406tg","通过"});
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1598954612406tg","通过"});
      this.curModelMap.put("提交审批", new String[]{"exclusiveGateway1598954612406tg","通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("通过", new String[]{"exclusiveGateway1560243367275tg","通过"});
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1560243367275tg","通过"});
      this.curModelMap.put("提交审批", new String[]{"exclusiveGateway1560243367275tg","通过"});
    }

    this.curAffixType = "bjlshbg";
    this.curAffixTypeCommon = "bjlshbg";
    this.setCommonData(true,null);
    // B报告
    managerAReportAffix = this.curTaskSingleAffix;
  }

  @Task("项目评审@办事处负责人审批")
  public void migrationBscfzrsp() throws Exception {

    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("提交审批", new String[]{"task1535433080256tjsh","提交审核"});
      this.curModelMap.put("通过", new String[]{"task1535433080256tjsh","提交审核"});
      this.curModelMap.put("提交融资部", new String[]{"task1535433080256tjsh","提交审核"});
      this.curModelMap.put("同意", new String[]{"task1535433080256tjsh","提交审核"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("提交审批", new String[]{"task1535531312595tg","提交审核"});
      this.curModelMap.put("通过", new String[]{"task1535531312595tg","提交审核"});
      this.curModelMap.put("提交融资部", new String[]{"task1535531312595tg","提交审核"});
      this.curModelMap.put("同意", new String[]{"task1535531312595tg","提交审核"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("提交审批", new String[]{"task1560243493708tjsh","提交审核"});
      this.curModelMap.put("通过", new String[]{"task1560243493708tjsh","提交审核"});
      this.curModelMap.put("提交融资部", new String[]{"task1560243493708tjsh","提交审核"});
      this.curModelMap.put("同意", new String[]{"task1560243493708tjsh","提交审核"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    }


    this.curAffixType = "tjfj";
    this.curAffixTypeCommon = this.curAffixType;

    this.setCommonData(true,null);
  }

  /**
   * 有两种界面
   */
  @Task("项目评审@部门风控经理审批")
  public void migrationBmfkjlsp() throws ScriptException, Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1571280591732ty","同意"});
      // 负责人独立审批签字
      this.curModelMap.put("报批", new String[]{"exclusiveGateway1571280591732ty","同意"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过", new String[]{"exclusiveGateway1575946801353tg","通过"});
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1575946801353tg","通过"});
      // 负责人独立审批签字
      this.curModelMap.put("报批", new String[]{"exclusiveGateway1575946801353tg","通过"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("通过", new String[]{"task1560243506597ty","同意"});
      this.curModelMap.put("同意", new String[]{"task1560243506597ty","同意"});
      // 负责人独立审批签字
      this.curModelMap.put("报批", new String[]{"task1560243506597ty","同意"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    }
    this.setBmfkjspData();
  }

  @Task("项目评审@负责人独立审批签字")
  public void migrationFzrdlspqz() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("同意", new String[]{"task1552639116522ty", "同意"});
      this.curModelMap.put("不同意", new String[]{"endbty", "不通过"});
      this.curModelMap.put("暂缓", new String[]{"endzh", "暂缓"});
      this.curModelMap.put("退回", new String[]{"task1535433080256th", "退回"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("同意", new String[]{"endty", "同意"});
      this.curModelMap.put("不同意", new String[]{"endbty", "不通过"});
      this.curModelMap.put("暂缓", new String[]{"endzh", "暂缓"});
      this.curModelMap.put("退回", new String[]{"task1535531312595th", "退回"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1560243423949tjsh", "提交审核"});
      this.curModelMap.put("不同意", new String[]{"endbtg", "不通过"});
      this.curModelMap.put("暂缓", new String[]{"endzh", "暂缓"});
    }
    this.setCommonData(false, null);
    this.setFinalApprovalData();
  }

  @Task("项目评审@分公司负责人审批")
  public void migrationFgsfzrsp() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("通过", new String[]{"exclusiveGateway1535451573279tjsh","提交审核"});
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1535451573279tjsh","提交审核"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过", new String[]{"exclusiveGateway1572947172618tg","通过"});
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1572947172618tg","通过"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("通过", new String[]{"exclusiveGateway1560243423949tjsh","提交审核"});
      this.curModelMap.put("同意", new String[]{"exclusiveGateway1560243423949tjsh","提交审核"});
      this.curModelMap.put("不通过", new String[]{"endbtg","不通过"});
    }

    this.curAffixType = "tjfj";
    this.curAffixTypeCommon = this.curAffixType;
    this.setCommonData(true,null);
  }

  @Task("项目评审@风控内勤设置D角")
  public void migrationFknqszDj() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("独立评审", new String[]{"exclusiveGateway1535682558814tjsh","提交审核"});
      this.curModelMap.put("上会审批", new String[]{"exclusiveGateway1535682558814tjsh","提交审核"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("独立评审", new String[]{"exclusiveGateway1567152133821tjsh","提交审核"});
      this.curModelMap.put("上会审批", new String[]{"exclusiveGateway1567152133821tjsh","提交审核"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("独立评审", new String[]{"exclusiveGateway1560248650964tjsh","提交审核"});
      this.curModelMap.put("上会审批", new String[]{"exclusiveGateway1560248650964tjsh","提交审核"});
    }

    this.setCommonData(false,null);
    this.setFknqszdj();
    if(this.curCustomData.get("reviewSecretary") != null){
      this.targetDbUtil.updateByParams("update nd_project_info set REVIEW_SECRETARY=? where id = ?"
          ,Arrays.asList(this.curCustomData.get("reviewSecretary").toString(),this.projectId));
    }
    this.reviewSecretary = this.curCustomData.get("reviewSecretary");
  }

  @Task("项目评审@独立评审D经理审核并投票")
  public void migrationDlpsDjlshbtp() throws Exception {
    this.curAffixType = "pstp";
    this.curAffixTypeCommon = this.curAffixType;

    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("投票", new String[]{"task1535433107939tp","投票"});
      this.actHiVarinstMap.put("nextnode", "task1535433107939");
      this.actHiVarinstMap.put("task1535433107939", "nd_huiqian");
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("投票", new String[]{"task1535703726061tp","投票"});
      this.actHiVarinstMap.put("nextnode", "task1535703726061");
      this.actHiVarinstMap.put("task1535703726061", "nd_huiqian");
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("投票", new String[]{"task1560243550276tp","投票"});
      this.curModelMap.put("退回", new String[] {"task1560243522142th","退回"});
      this.actHiVarinstMap.put("nextnode", "task1560243550276");
      this.actHiVarinstMap.put("task1560243550276", "nd_huiqian");
    }

    this.setCommonData(true,null);
    this.setVoteCustomData();
    this.setMultipleRoleIdData(true);
    this.setABResportFileData();
  }

  @Task("项目评审@独立评审委员投票")
  public void migrationDlpswytp() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("all", new String[]{"task1535433116401tj","提交"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("all", new String[]{"task1535703769096xyb","下一步"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("all", new String[]{"task1560243561136tj","提交"});
    }
    this.curAffixType = "pstp";
    this.curAffixTypeCommon = this.curAffixType;
    this.setCommonData(true,null);
    this.setVoteCustomData();

//    this.actHiVarinstMap.put("task1535433116401",this.reviewSecretary);
//    this.actHiVarinstMap.put("nextUserName",this.reviewSecretary);

    String[] reviewSecretaryArr = BusinessTool.getEmpCodeAndNameSeperated(this.getJbpmVarInstValueByName("auditSecretor"),"|", ",", this.curJbpmTaskInstanceRow.get("CREATE_"));
    this.curProcessData.replace("next_step_user", reviewSecretaryArr == null ? null : reviewSecretaryArr[0]+"("+reviewSecretaryArr[1]+")");

    this.setABResportFileData();
  }

  @Task("项目评审@审保秘书汇总意见")
  public void migrationSbmshzyj() throws ScriptException, Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("all",new String[]{"exclusiveGateway1546497310974tg","通过"});
    } else if(auditType.equals("项目展期评审")) {
//      this.curModelMap.put("转上会",new String[]{"task1535530921953tjsh","提交上会"});
//      this.curModelMap.put("通过",new String[]{"task1535703813100tg","通过"});
      this.curModelMap.put("all",new String[]{"task1535703813100tg","通过"});
    } else if(auditType.equals("项目复议评审")) {
//      this.curModelMap.put("转上会",new String[]{"task1560243655208zsh","转上会"});
//      this.curModelMap.put("通过",new String[]{"exclusiveGateway1560243578977tg","通过"});
//      this.curModelMap.put("不通过",new String[]{"endbtg","不通过"});
      this.curModelMap.put("all",new String[]{"exclusiveGateway1560243578977tg","通过"});
    }
    this.setPsjlData();
    this.setReviewSecretaryCandidateIdentityLink();

  }

  @Task("项目评审@独立评审总经理审批签字")
  public void migrationDlpszjlspqz() throws Exception {
    if(auditType.equals("调查报告评审")) {
      // 独立评审总经理审批签字
      this.curModelMap.put("通过",new String[]{"exclusiveGateway1535448060981tg","通过"});
      // 独立评审董事长审批签字
      this.curModelMap.put("同意",new String[]{"task1552639116522ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
      this.curModelMap.put("不同意且不许复议",new String[]{"endbtyqbxfy","不同意且不许复议"});
      this.curModelMap.put("暂缓",new String[]{"endzh","暂缓"});
      this.curModelMap.put("退回",new String[]{"task1535433116401th","退回"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过",new String[]{"task1535703832540tg","通过"});
      this.curModelMap.put("同意",new String[]{"endty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
//      this.curModelMap.put("退回",new String[]{"task1535433116401th","退回"});
    } else if(auditType.equals("项目复议评审")) {
      // 独立评审总经理审批签字
      this.curModelMap.put("同意",new String[]{"exclusiveGateway1560243599585tg","通过"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
      this.curModelMap.put("暂缓",new String[]{"endzh","暂缓"});
      this.curModelMap.put("退回",new String[]{"task1560243561136th","退回"});
    }

    this.setCommonData(false,null);
    this.setFinalApprovalData();
  }

  /**
   * 设置最终审批结果数据
   */
  public void setFinalApprovalData() throws Exception {
    Map wfAffixNotionObjWkFlagTwo = this.findFirstWfAffixNotionObjByWkflag(2);
    if(wfAffixNotionObjWkFlagTwo != null) {
      // 同意担保金额
      this.curCustomData.put("applyCoverage", wfAffixNotionObjWkFlagTwo.get("STRESTIMATE"));
      // 项目授信期限
      this.curCustomData.put("applyTime", BusinessTool.convertApplyTimeToMonth(wfAffixNotionObjWkFlagTwo.get("STRRESULT")));
    }
    // 评审结论附件
    this.setSingleProjectAffixCustomData(this.reviewConclusionReportAffix,"Psjl");

    // AB评审报告
    this.setABResportFileData();

    this.setGuaranteeInfo();
  }

  @Task("项目评审@独立评审董事长审批签字")
  public void migrationDlpsdszspqz() throws Exception {
    this.migrationDlpszjlspqz();
    if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("同意",new String[]{"endty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
//      this.curModelMap.put("退回",new String[]{"task1535433116401th","退回"});
    }
  }

  // ====================================================== 上会流程 =========================================================//
  @Task("项目评审@C经理提交风险审核报告")
  public void migrationCJltjfxshbg() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("通过",new String[]{"task1535433063214tg","通过"});
      this.curModelMap.put("不通过",new String[]{"endbty","不通过"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过",new String[]{"task1535530893755tg","通过"});
      this.curModelMap.put("不通过",new String[]{"endbty","不通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("通过",new String[]{"task1560243835689tg","通过"});
      this.curModelMap.put("不通过",new String[]{"endbtg","不通过"});
    }
    this.curAffixType = "cjlshbg";
    this.curAffixTypeCommon = this.curAffixTypeCommon;
    this.setCommonData(true,null);
  }

  @Task("项目评审@公司融资部审批")
  public void migrationGsrzbsp() throws Exception {

    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("通过",new String[]{"task1535433078572tg","通过"});
      this.curModelMap.put("不通过",new String[]{"endbty","不通过"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过",new String[]{"task1535533444991tg","通过"});
      this.curModelMap.put("不通过",new String[]{"endbtg","不通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("通过",new String[]{"task1560243522142tg","通过"});
      this.curModelMap.put("不通过",new String[]{"endbtg","不通过"});
    }

    this.curAffixTypeCommon = this.curAffixTypeCommon;
    this.setCommonData(false,null);
  }

  /**
   * 林业项目评审流程独有环节
   */
  @Task("项目评审@林业项目部审批")
  public void migrationLyxmbsp() throws Exception {
    this.migrationGsrzbsp();
  }

  @Task("项目评审@D经理审核评审报告")
  public void migrationDJlshpsbg() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("通过",new String[]{"task1535433097680tg","通过"});
      this.actHiVarinstMap.put("nextnode","task1535433097680");
      this.actHiVarinstMap.put("task1535433097680","nd_huiqian");
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过",new String[]{"task1535703625372tg","通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("通过",new String[]{"task1560243639901tg","通过"});
      this.curModelMap.put("退回",new String[]{"task1560243522142th","退回"});
      this.actHiVarinstMap.put("nextnode","task1560243639901");
      this.actHiVarinstMap.put("task1560243639901","nd_huiqian");
    }

    this.curAffixType = "tjfj";
    this.setCommonData(true,null);
    this.setMultipleRoleIdData(true);
    // TODO: 外审报告评级和说明(老系统中没有此数据)
    // 外审报告评级
    this.curCustomData.put("rating","");
    // 评级说明
    this.curCustomData.put("rating_description","");



    this.setABResportFileData();
  }

  @Task("项目评审@风控责任人审核")
  public void migrationFkzrrsh() throws Exception {

    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("通过",new String[]{"task1535433101491tg","通过"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("通过",new String[]{"task1535703670895tg","通过"});
      this.curModelMap.put("退回",new String[]{"task1535533596374th","退回"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("通过",new String[]{"task1560243655208tg","通过"});
    }
    this.setCommonData(false,null);
  }

  @Task("项目评审@上会前总经理审核")
  public void migrationShqzjlsh() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("同意",new String[]{"task1535433103583ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("同意",new String[]{"task1535703693232ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("同意",new String[]{"task1560243672091ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
    }
    this.setCommonData(false,null);
  }

  @Task("项目评审@评审会主任审核")
  public void migrationPshzrsh() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("同意",new String[]{"task1535433311622ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
      this.curModelMap.put("不同意且不许复议",new String[]{"endbtyqbxfy","不同意且不许复议"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("同意",new String[]{"task1535530921953ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("同意",new String[]{"task1560243915664ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
      this.curModelMap.put("不同意且不许复议",new String[]{"endbtyqbxfy","不同意且不许复议"});
    }
    this.setCommonData(false,null);
  }

  @Task("项目评审@评审秘书确定评审委员")
  public void migrationPsmsqdpswy() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("只发资料",new String[]{"task1535433314226tjps","提交评审"});
      this.curModelMap.put("提交评审",new String[]{"task1535433314226tjps","提交评审"});
      this.actHiVarinstMap.put("nextnode", "task1535433314226");
      this.actHiVarinstMap.put("task1535433314226", "nd_huiqian");
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("只发资料",new String[]{"task1535531008710tjps","提交评审"});
      this.curModelMap.put("提交评审",new String[]{"task1535531008710tjps","提交评审"});
      this.actHiVarinstMap.put("nextnode", "task1535531008710");
      this.actHiVarinstMap.put("task1535531008710", "nd_huiqian");
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("只发资料",new String[]{"task1560243910374zfzl","只发资料"});
      this.curModelMap.put("提交评审",new String[]{"task1560243913751tjps","提交评审"});
      this.actHiVarinstMap.put("nextnode", "task1560243913751");
      this.actHiVarinstMap.put("task1560243913751", "nd_huiqian");
    }

    this.setCommonData(false,null);
    this.setMultipleRoleIdData(true);
    this.setReviewSecretaryCandidateIdentityLink();
  }

  @Task("项目评审@评审委员提交意见")
  public void migrationPswytjyj() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("all",new String[]{"task1535433316115xyb","下一步"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("all",new String[]{"task1535531061729xyb","下一步"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("all",new String[]{"task1560243910374xyb","下一步"});
    }

    this.curAffixType = "pstp";
    this.curAffixTypeCommon = this.curAffixType;
    this.setCommonData(false,null);
    this.setVoteCustomData();
  }

  @Task("项目评审@评审秘书提交会议纪要")
  public void migrationPsmstjhyjy() throws ScriptException, Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("all",new String[]{"task1562220491234tj","提交"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("all",new String[]{"task1535703857767tg","通过"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("all",new String[]{"task1560243682253tj","提交"});
    }
    this.setPsjlData();
    this.setReviewSecretaryCandidateIdentityLink();
  }

  @Task("项目评审@评审会主任审批签字")
  public void migrationPshzrspqz() throws Exception {
    if(auditType.equals("调查报告评审")) {
      this.curModelMap.put("同意",new String[]{"task1552639116522ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
      this.curModelMap.put("暂缓",new String[]{"endzh","暂缓"});
      this.curModelMap.put("退回",new String[]{"task1535433316115th","退回"});
    } else if(auditType.equals("项目展期评审")) {
      this.curModelMap.put("同意",new String[]{"endty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
      this.curModelMap.put("退回",new String[]{"task1535531061729th","退回"});
    } else if(auditType.equals("项目复议评审")) {
      this.curModelMap.put("同意",new String[]{"task1560243792023ty","同意"});
      this.curModelMap.put("不同意",new String[]{"endbty","不同意"});
      this.curModelMap.put("暂缓",new String[]{"endzh","暂缓"});
      this.curModelMap.put("退回",new String[]{"task1560243910374th","退回"});
    }
    this.setCommonData(false,null);
    this.setFinalApprovalData();
  }

  @Task("项目评审@风控经理独立审批")
  public void migrationFkjldlsp() throws Exception {
    //  TODO: 新流程中还未找到对应的环节
    this.curModelMap.put("报批",new String[]{"task1552639116522ty","同意"});
    this.curModelMap.put("不通过",new String[]{"endbty","不同意"});
    Map wfAffixNotioObjWkFlagThree = this.findFirstWfAffixNotionObjByWkflag(3);
    this.setCommonData(true,wfAffixNotioObjWkFlagThree == null ? "" : wfAffixNotioObjWkFlagThree.get("INTMARK").toString());
    this.setApprovalResultAndReviewConclusion(false);
  }

  /**
   * 设置AB报告数据
   */
  private void setABResportFileData() throws Exception {
    this.setSingleProjectAffixCustomData(this.managerAReportAffix,"A");
    this.setSingleProjectAffixCustomData(this.managerBReportAffix,"B");
  }

  public void setReviewSecretaryCandidateIdentityLink() {
    if(this.reviewSecretary != null) {
      String[] rsArr = reviewSecretary.toString().split(",");
      if(rsArr.length > 1) {
        for (String reviewSecretarySingle : rsArr) {
          if (this.actHiIdentityLinkMap.get(this.curJbpmTaskInstanceId).get("candidate") == null) {
            this.actHiIdentityLinkMap.get(this.curJbpmTaskInstanceId).put("candidate", reviewSecretarySingle);
          } else {
            this.actHiIdentityLinkMap.get(this.curJbpmTaskInstanceId).put("candidate", reviewSecretarySingle + ","
                + this.actHiIdentityLinkMap.get(this.curJbpmTaskInstanceId).get("candidate"));
          }
        }
      } else {
        this.actHiIdentityLinkMap.get("process").put("participant", rsArr[0]);
      }
    }
  }

}
